<?php
class ModelMartCrmmonthreport extends Model {
    
    public function Good($data = array()) { 
		echo $data['filter_date_start'].$data['filter_date_end'];
	}
	public function getMonthReport($data = array()) { 
		$sql = "SELECT crm_customer_transactions.id, MONTH( bill_date ) AS name, SUM( crm_customer_transactions.amount ) AS amount\n
                    FROM crm_customer_transactions, crm_customer_bills, crm_customer_transactions_crm_customer_bills_c\n
                    WHERE crm_customer_bills.id = crm_customer_transactions_crm_customer_bills_c.crm_custom19b9r_bills_ida\n
                    AND crm_customer_transactions.id = crm_customer_transactions_crm_customer_bills_c.crm_customaf9eactions_idb\n
                    AND YEAR( bill_date ) = '";
                    if (!empty($data['filter_group'])) {
                                $sql .= $this->db->escape($data['filter_group']) . "'\n";

                        }
                    $sql .= " GROUP BY MONTH( bill_date )";
		//$sql = "select * from accounts";
                //echo $sql;
		$query = $this->db->query($sql);
		return $query->rows;
                echo $query;
	}

	public function getTotalCustomersOnline($data = array()) {
		$sql = "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "customer_online` co LEFT JOIN " . DB_PREFIX . "customer c ON (co.customer_id = c.customer_id)";
		
		$implode = array();
		
		if (isset($data['filter_ip']) && !is_null($data['filter_ip'])) {
			$implode[] = "co.ip LIKE '" . $this->db->escape($data['filter_ip']) . "'";
		}
		
		if (isset($data['filter_customer']) && !is_null($data['filter_customer'])) {
			$implode[] = "co.customer_id > 0 AND CONCAT(c.firstname, ' ', c.lastname) LIKE '" . $this->db->escape($data['filter_customer']) . "'";
		}
		
		if ($implode) {
			$sql .= " WHERE " . implode(" AND ", $implode);
		}
				
		$query = $this->db->query($sql);

		return $query->row['total'];
	}
}
?>